/**
 * 
 */
package com.jeecms.wicool.dao.question.impl;

import org.apache.commons.lang.StringUtils;

import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.question.UserReportDao;
import com.jeecms.wicool.entity.question.UserReport;

/**
 * @author spring
 *
 */
public class UserReportDaoImpl extends HibernateBaseDao<UserReport, Integer> implements
		UserReportDao {

	@Override
	public Pagination getPage(String userName, String title, String mobile,
			String beginTime, String endTime, int pageNo, int pageSize) {
		 Finder f = Finder.create("select bean from UserReport bean where 1=1");

	        if (StringUtils.isNotBlank(title)) {
	            f.append(" and bean.title = :title");
	            f.setParam("title", title);
	        }
	        if (StringUtils.isNotBlank(userName)) {
	            f.append(" and bean.user.name like :userName");
	            f.setParam("userName", "%"+userName+"%");
	        }
	        if (StringUtils.isNotBlank(mobile)) {
	            f.append(" and bean.user.mobile = :mobile");
	            f.setParam("mobile", Long.valueOf(mobile));
	        }
	        
	        if(StringUtils.isNotBlank(beginTime)){
	        	 f.append(" and bean.createTime >= '"+beginTime+" 00:00:00'");
	        }
	        
	        if(StringUtils.isNotBlank(endTime)){
	        	f.append(" and bean.createTime <= '"+endTime+" 23:59:59'");
	        }
	        
	        f.append(" order by bean.createTime desc");
	        return find(f, pageNo, pageSize);
	}

	@Override
	protected Class<UserReport> getEntityClass() {
		return UserReport.class;
	}

}
